
# This trigger is meant to disallow filenames that may cause problems with
# unix and windows filesystems, independently from what svn may or may not
# disallow itself)

import svn.fs

# Disallow all kinds of whitespace (space, tab, nl)
BADCHARS_WS=" \t\n"
# These make windows unhappy
BADCHARS_OTHER='*?\\:;'
BADCHARS = BADCHARS_WS + BADCHARS_OTHER

def RunHook(hi, logger):

  for (path, cl) in hi.paths_changed.iteritems():
    # TODO(epg): Add unit test for this.
    # If the file already got in somehow, any damage is already done.
    # And we certainly want folks to be able to remove paths with bad
    # names.  So we only block adds.
    if cl.change_kind != svn.fs.path_change_add:
      continue

    for char in BADCHARS:
      #print "looking for %s in %s" % (char, path)
      if char in path:
        error = "'%s' is forbidden in pathname '%s'" % (char, path)
	logger.warning(error)
	return error

  return 0
